def beautify_excel(filename, columns):
    import openpyxl
    from openpyxl.styles import Alignment, PatternFill, Border, Side, Font

    # 打开工作簿
    workbook = openpyxl.load_workbook(filename)
    worksheet = workbook.active

    # 设置列宽
    widths = [20, 10, 10, 30, 25, 50, 10]  # 对应列的宽度
    for col, width in zip(columns, widths):
        col_idx = columns.index(col)
        worksheet.column_dimensions[openpyxl.utils.get_column_letter(col_idx + 1)].width = width

    # 设置表头格式
    header_format = openpyxl.styles.NamedStyle(
        name="header_format",
        alignment=Alignment(horizontal="center", vertical="center"),
        fill=PatternFill(start_color="DCDCDC", end_color="DCDCDC", fill_type="solid"),
        font=Font(bold=True, size=12),
        border=Border(
            left=Side(style="thin", color="000000"),
            right=Side(style="thin", color="000000"),
            top=Side(style="thin", color="000000"),
            bottom=Side(style="thin", color="000000"),
        ),
    )

    # 应用表头格式
    for col_num, col_name in enumerate(columns):
        cell = worksheet.cell(row=1, column=col_num + 1, value=col_name)
        cell.style = header_format

    # 设置单元格格式
    cell_format = openpyxl.styles.NamedStyle(
        name="cell_format",
        alignment=Alignment(horizontal="center", vertical="center"),
        border=Border(
            left=Side(style="thin", color="000000"),
            right=Side(style="thin", color="000000"),
            top=Side(style="thin", color="000000"),
            bottom=Side(style="thin", color="000000"),
        ),
    )

    # 应用单元格格式
    for row in worksheet.iter_rows(min_row=2, max_row=worksheet.max_row, min_col=1, max_col=len(columns)):
        for cell in row:
            cell.style = cell_format

    # 保存工作簿
    workbook.save(filename)
    print(f"表格已美化并保存到 {filename}")